package com.nekonomics
package utils.magic

//import scala.deriving.*

import scala.compiletime.{constValue, erasedValue, summonInline}
import scala.quoted.*

object TypeMagic {


  inline def fieldNames[T]: List[String] = ${ fieldNamesImpl[T] }

  inline def typeName[T]: String = ${ typeNameImpl[T] }
  

  private def fieldNamesImpl[T: Type](using q: Quotes): Expr[List[String]] =
    Expr(getFieldNames[T])

  private def typeNameImpl[T: Type](using q: Quotes): Expr[String] =
    Expr(getTypeName[T])


  private[magic] def getFieldNames[T: Type](using q: Quotes): List[String] = {
    import q.reflect.*
    val sym = TypeRepr.of[T].typeSymbol
    if !sym.isClassDef || !sym.flags.is(Flags.Case) then
      report.warning("note that selectFields only works with case classes");
      Nil
    else
      sym.caseFields.map(_.name)
  }

  private[magic] def getTypeName[T: Type](using q: Quotes): String = {
    import q.reflect.*
    TypeRepr.of[T].typeSymbol.name
  }


}
